package org.spiderflow.config.exception;


import org.spiderflow.config.GlobalErrorInfoEnum;
import org.spiderflow.config.RestResultGenerator;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by dyl on 2019/05/21.
 */
@RestControllerAdvice
public class CustomExtHandler {

    /**
     * 捕捉所有异常
     * @param e
     * @param request
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    Object handleException(Exception e, HttpServletRequest request){
        e.printStackTrace();
        return RestResultGenerator.genErrorResult(GlobalErrorInfoEnum.NETWORK_BUSY);
    }

    /**
     * 捕捉自定义异常
     * @param e
     * @param request
     * @return
     */
    @ExceptionHandler(value = ExecptionWhole.class)
    Object execptionWhole(ExecptionWhole e, HttpServletRequest request){
        e.printStackTrace();
//       return new ResponseEntity<Object>(e.getCode(),HttpStatus.INTERNAL_SERVER_ERROR);
        return RestResultGenerator.genErrorResult(e.getCode(),"",e.getMsg());
     } 

}